package com.neu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neu.common.utils.SecurityUtils;
import com.neu.system.domain.vo.NeuTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.enums.BusinessType;
import com.neu.system.domain.NeuTask;
import com.neu.system.service.INeuTaskService;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.common.core.page.TableDataInfo;

/**
 * 用户反馈异常Controller
 *
 */
@Api(tags = "任务控制")
@RestController
@RequestMapping("/system/task")
public class NeuTaskController extends BaseController
{
    @Autowired
    private INeuTaskService neuTaskService;

    /**
     * 查询历史反馈信息
     */
    @ApiOperation("查询历史反馈信息")
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(NeuTask neuTask)
    {

        List<NeuTaskVo> list = neuTaskService.selectNeuTaskList(neuTask);

        TableDataInfo dataTable = getDataTable(list);
        Long total = neuTaskService.getHistoryCount(neuTask);
        dataTable.setTotal(total);
        return dataTable;
    }

    /**
     * 导出历史反馈记录
     */
    @PreAuthorize("@ss.hasPermi('system:task:export')")
    @Log(title = "导出历史反馈记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NeuTask neuTask)
    {
        List<NeuTaskVo> list = neuTaskService.selectNeuTaskList(neuTask);
        ExcelUtil<NeuTaskVo> util = new ExcelUtil<NeuTaskVo>(NeuTaskVo.class);
        util.exportExcel(response, list, "用户反馈数据");
    }

    /**
     * 根据id获取反馈信息
     */
    @PreAuthorize("@ss.hasPermi('system:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(neuTaskService.selectNeuTaskById(id));
    }

    /**
     * 用户提交反馈信息
     */
    @ApiOperation("用户提交反馈信息")
    @Log(title = "用户提交反馈信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult userCommit(@RequestBody NeuTask neuTask)
    {
        return toAjax(neuTaskService.insertNeuTask(neuTask));
    }

    @GetMapping("/getone/{id}")
    public AjaxResult getTaskById(@PathVariable Long id) {
        NeuTaskVo vo = neuTaskService.getOneId(id);
        return AjaxResult.success(vo);
    }

    /**
     * 获取当前用户历史举报数据
     * @return
     */
    @GetMapping
    public AjaxResult getLoginUserAgo() {
        List<NeuTaskVo> result = neuTaskService.getUserCommitHistory();
        return AjaxResult.success(result);
    }

    /**
     * 获取待分配列表
     */
    @ApiOperation("获取待分配列表")
    @PreAuthorize("@ss.hasPermi('system:task:send')")
    @GetMapping("/getsend")
    public TableDataInfo getSend(NeuTask neuTask)
    {
        startPage();
        List<NeuTaskVo> list = neuTaskService.getNoSend(neuTask);

        TableDataInfo dataTable = getDataTable(list);
        Long count = neuTaskService.getHistoryCount(neuTask);
        dataTable.setTotal(count);
        return dataTable;
    }

    /**
     * 反馈分配
     */
    @ApiOperation("反馈分配")
    @PreAuthorize("@ss.hasPermi('system:task:send')")
    @Log(title = "反馈分配", businessType = BusinessType.UPDATE)
    @PutMapping("/send")
    public AjaxResult edit(@RequestBody NeuTask neuTask)
    {
        return toAjax(neuTaskService.updateNeuTask(neuTask));
    }

    /**
     * 获取待处理列表
     */
    @ApiOperation("获取待处理列表")
    @PreAuthorize("@ss.hasPermi('system:task:handle')")
    @GetMapping("/gethandle")
    public TableDataInfo getHandle(NeuTask neuTask)
    {
        startPage();
        List<NeuTaskVo> list = neuTaskService.getNoHandle(neuTask);

        TableDataInfo dataTable = getDataTable(list);
        Long count = neuTaskService.getHistoryCount(neuTask);
        dataTable.setTotal(count);
        return dataTable;
    }

    /**
     * 反馈处理
     */
    @ApiOperation("反馈处理")
    @PreAuthorize("@ss.hasPermi('system:task:commit')")
    @Log(title = "反馈处理", businessType = BusinessType.UPDATE)
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody NeuTask neuTask)
    {
        return toAjax(neuTaskService.handleNeuTask(neuTask));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:task:remove')")
    @Log(title = "删除反馈数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(neuTaskService.deleteNeuTaskByIds(ids));
    }
}

